﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.BLL
{
    public class FieldSpecificationBLL : IFieldSpecificationBLL
    {
        private static readonly IFieldSpecificationDAL dal = DataAccess.CreateFieldSpecifications();
        private static readonly IFieldDAL fieldDAL = DataAccess.CreateFields();
        private static readonly IClassDAL classDAL = DataAccess.CreateClasses();

        private FieldInfo fieldInfo = new FieldInfo();
        private ClassInfo classInfo = new ClassInfo();
        public IList<FieldSpecificationInfo> ListFieldSpecification()
        {
            return dal.ListFieldSpecification(new FieldSpecificationInfo(0));
        }

        public IList<FieldSpecificationInfo> ListFieldSpecification(string Sequence)
        { 
            int Seq = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            return dal.ListFieldSpecification(new FieldSpecificationInfo(Seq));
        }
        public IList<FieldSpecificationInfo> ListFieldSpecificationByField(string Field)
        {
            fieldInfo.Sequence = Field.Length > 0 ? Int32.Parse(Field) : 0;
            return dal.ListFieldSpecification(new FieldSpecificationInfo(0, fieldInfo, classInfo, "", "", null, null));
        }
        public IList<FieldSpecificationInfo> ListFieldSpecificationByField(string Field, string ClassNo)
        {
            fieldInfo.Sequence = Field.Length > 0 ? Int32.Parse(Field) : 0;
            classInfo.Sequence = ClassNo.Length > 0 ? Int32.Parse(ClassNo) : 0;

            return dal.ListFieldSpecification(new FieldSpecificationInfo(0, fieldInfo, classInfo, "", "", null, null));
        }
        public void Insert(string Field, string ClassNo, string Remarks, int CreatedBy)
        {
            try
            {
                fieldInfo.Sequence = Field.Length > 0 ? Int32.Parse(Field) : 0;
                classInfo.Sequence = ClassNo.Length > 0 ? Int32.Parse(ClassNo) : 0;

                dal.Insert(new FieldSpecificationInfo(0, fieldInfo, classInfo, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Field, string ClassNo, string Remarks, int UpdatedBy)
        {
            try
            {
                fieldInfo.Sequence = Field.Length > 0 ? Int32.Parse(Field) : 0;
                classInfo.Sequence = ClassNo.Length > 0 ? Int32.Parse(ClassNo) : 0;

                dal.Update(new FieldSpecificationInfo(Sequence, fieldInfo, classInfo, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                dal.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
